package com.sgb.kjwl.view.ui.activity.leaseAsk;

import android.content.Context;
import android.content.Intent;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityAskLeaseForRentBinding;
import com.sgb.kjwl.di.machine.DaggerMachineComponent;
import com.sgb.kjwl.di.machine.MachineModule;
import com.sgb.kjwl.view.ui.fragment.machine.AskLeaseHallFragment;
import com.sgb.kjwl.viewmodel.machine.AskLeaseModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;

import javax.inject.Inject;

/**
 * 求租大厅(需求大厅)
 */
public class AskLeaseActivity extends AppActivity {

    @Inject
    AskLeaseModel viewModel;

    private ActivityAskLeaseForRentBinding binding;
    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private String[] titles = {"求租信息", "竞价租赁", "集采租赁"};
    private int position;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerMachineComponent.builder().appComponent(appComponent)
                .machineModule(new MachineModule(this))
                .build()
                .inject(this);
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, AskLeaseActivity.class);
        context.startActivity(intent);
    }

    public static void start(Context context, int position) {
        Intent intent = new Intent();
        intent.putExtra("position", position);
        intent.setClass(context, AskLeaseActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_ask_lease_for_rent);
        position = getIntent().getIntExtra("position", 0);
        binding.ivBack.setVisibility(View.VISIBLE);
        binding.ivBack.setOnClickListener(view -> finish());
    }

    @Override
    protected void init() {
        mFragments = new ArrayList<>();
        mFragments.add(AskLeaseHallFragment.newInstance(0,true));//需求大厅
        mFragments.add(AskLeaseHallFragment.newInstance(1,true));//竞价租赁
        mFragments.add(AskLeaseHallFragment.newInstance(2,true));//集采租赁
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setOffscreenPageLimit(titles.length);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.tablayout.setViewPager(binding.viewpager, titles);
        binding.viewpager.setCurrentItem(position);
    }

}
